package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.HumanNeeds;
import cn.wolfcode.crm.query.HumanNeedsQueryForObject;
import cn.wolfcode.crm.service.IHumanNeedsService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PageResult;
import cn.wolfcode.crm.util.PermissionName;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("humanNeeds")
public class HumanNeedsController {
    @Autowired
    private IHumanNeedsService humanNeedsService;

    /*创建一个方法来确定*/
    @RequestMapping("index")
    public String index(){
        //查找到并共享
        return "humanNeeds/list";
    }
    @RequiresPermissions("humanNeeds:list")
    @PermissionName("用人需求列表")
    @ResponseBody
    @RequestMapping("list")
    public PageResult list(HumanNeedsQueryForObject qo){
        return humanNeedsService.query(qo);
    }

    /**
     *
     * @param humanNeeds 保存班级管理
     * @return 返回json
     */
    @RequiresPermissions("humanNeeds:save")
    @PermissionName("用人需求保存")
    @ResponseBody
    @RequestMapping("save")
    public JsonResult save(HumanNeeds humanNeeds){
        JsonResult result = new JsonResult();
        try {
            humanNeedsService.insert(humanNeeds);
        }catch (Exception e){
            e.printStackTrace();
            result = new JsonResult("保存失败");
        }
        return result;
    }
    @RequiresPermissions("humanNeeds:update")
    @PermissionName("用人需求更新")
    @ResponseBody
    @RequestMapping("update")
    public JsonResult update(HumanNeeds humanNeeds){
        JsonResult result = new JsonResult();
        try {
            humanNeedsService.updateByPrimaryKey(humanNeeds);
        }catch (Exception e){
            e.printStackTrace();
            result = new JsonResult("更新失败");
        }
        return result;
    }
}
